package com.han.hotelplat.dao.emtask;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.han.hotelplat.comm.base.BaseDAO;
import com.han.hotelplat.pojo.emtask.Emtask;

@Repository
public class EmtaskDao extends BaseDAO<Emtask>{

	//查询对该任务接单的帮工列表
	public List<Emtask> getEmTaskByTaskid(String taskid) {
		String hql = "select new Emtask(emt.emid,em.realname,em.tel,emt.taskid,emt.canceltime, em.area, em.pushkey, emt.isstop) from Emtask as emt, Employee as em , Task as t "
				+ " where t.taskid = emt.taskid and em.userid = emt.emid and  (emt.canceltime is null or (t.state = 7 and emt.canceltime >= emt.starttime))  and  emt.taskid='"+taskid+"'";
		return findByHQL(hql);
	}

	public List<Emtask> getMyTaskByUserid(String userid) {
		String hql = "from Emtask where canceltime is null and emid ='"+userid
				+"' order by endtime ASC";
		return findByHQL(hql);
	}
	
	public Emtask getEmTask(String taskid, String userid) {
		String hql = "from Emtask as emt "
				+ " where 1=1 "
				+ " and emt.emid='"+userid+"'"
				+ " and emt.taskid='"+taskid+"'";
		List<Emtask> re = findByHQL(hql);
		return re.size()==0?null:re.get(0);
	}
}
